use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};

#[get("/")]
async fn hello() -> impl Responder {
  HttpResponse::Ok().body("Hello world!")
}
pub async fn health_check_handler() -> impl Responder {
  HttpResponse::Ok().json("Health check.")
}

pub fn general_routes(cfg: &mut web::ServiceConfig) {
  cfg.route("/health", web::get().to(health_check_handler));
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
  let app = move || App::new().service(hello).configure(general_routes);

  println!("\nServer is running on http://127.0.0.1:8080\n");
  HttpServer::new(app).bind(("127.0.0.1", 8080))?.run().await
}
